package com.hymjweb.demo.hymj.basic_data_manage.xt_airlines.add_cost_detail.mapper;

import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.basic_data_manage.xt_airlines.add_cost_detail.bean.XtAirlinesAddCostDetailPojo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


@Mapper
@Component
public interface XtAirlinesAddCostDetailMapper {

    class XtAirlinesAddCostDetailMapperProvider{

        public String findAll(Map map) {

            String sql= new SQL() {{
                SELECT("t.*");
                FROM("xt_airlines_add_cost_detail t");
                WHERE("1 = 1");
            }}.toString();
            String airlinesId = DataTypeUtil.toNotNullString(map.get("airlinesId"));
            if(!DataTypeUtil.isEmptyStr(airlinesId)){
                sql += " and t.airlines_id = " + DataTypeUtil.quoteStr(airlinesId);
            }
            return  sql;
        }

        public String insert(XtAirlinesAddCostDetailPojo pojo) {
            String sql = new SQL() {{
                INSERT_INTO("xt_airlines_add_cost_detail");
                VALUES("id","#{id}");
                VALUES("airlines_id","#{airlinesId}");
                VALUES("name","#{name}");
                VALUES("price","#{price}");
                VALUES("ticket_price","#{ticketPrice}");
                VALUES("comment","#{comment}");
                VALUES("create_time", "#{createTime}");
                VALUES("create_user_id", "#{createUserId}");
                VALUES("update_time", "#{updateTime}");
                VALUES("update_user_id", "#{updateUserId}");
            }}.toString();
            return sql;
        }

        public String update(XtAirlinesAddCostDetailPojo pojo) {
            String sql= new SQL() {{
                UPDATE("xt_airlines_add_cost_detail t");
                SET("t.id = #{id}");
                SET("t.airlines_id = #{airlinesId}");
                SET("t.name = #{name}");
                SET("t.price = #{price}");
                SET("t.ticket_price = #{ticketPrice}");
                SET("t.comment = #{comment}");
                SET("t.update_time = #{updateTime}");
                SET("t.update_user_id = #{updateUserId}");
                WHERE("t.id=#{id}");
            }}.toString();
            return sql;
        }

        public String delete(String id) {
            String sql = new SQL() {{
                DELETE_FROM("xt_airlines_add_cost_detail");
                WHERE("id = " + id );
            }}.toString();
            return sql;
        }

        public String findUK(String name,String airlinesId, String exceptId) {

            String sql= new SQL() {{
                SELECT("t.id,t.name,t.airlines_id");
                FROM("xt_airlines_add_cost_detail t");
                WHERE(" t.name = " + DataTypeUtil.quoteStr(name));
                WHERE(" t.airlines_id = " + DataTypeUtil.quoteStr(airlinesId));
            }}.toString();

            if(!DataTypeUtil.isEmptyStr(exceptId)){
                sql += " and t.id != " + DataTypeUtil.quoteStr(exceptId);
            }

            return  sql;
        }

        public String findByAirlinesId(String airlinesId) {

            String sql= new SQL() {{
                SELECT("t.*");
                FROM("xt_airlines_add_cost_detail t");
                WHERE("1 = 1");
            }}.toString();
            if(!DataTypeUtil.isEmptyStr(airlinesId)){
                sql += " and t.airlines_id = " + DataTypeUtil.quoteStr(airlinesId);
            }
            return  sql;
        }

    }

    @InsertProvider(type = XtAirlinesAddCostDetailMapperProvider.class, method = "insert")
    int insert(XtAirlinesAddCostDetailPojo pojo);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @UpdateProvider(type = XtAirlinesAddCostDetailMapperProvider.class, method = "update")
    int update(XtAirlinesAddCostDetailPojo obj);

    @Results(id = "xtAirlinesAddCostMapId",value = {
            @Result(column = "id", property = "id"),
            @Result(column = "airlines_id", property = "airlinesId"),
            @Result(column = "name", property = "name"),
            @Result(column = "price", property = "price"),
            @Result(column = "ticket_price", property = "ticketPrice"),
            @Result(column = "comment", property = "comment"),
    })
    @SelectProvider(type = XtAirlinesAddCostDetailMapperProvider.class, method = "findAll")
    List<XtAirlinesAddCostDetailPojo> findAll(Map map);

    @Results(id = "xtAirlinesAddCostFindByAirlinesIdMapId",value = {
            @Result(column = "id", property = "id"),
            @Result(column = "airlines_id", property = "airlinesId"),
            @Result(column = "name", property = "name"),
            @Result(column = "price", property = "price"),
            @Result(column = "ticket_price", property = "ticketPrice"),
            @Result(column = "comment", property = "comment"),
    })
    @SelectProvider(type = XtAirlinesAddCostDetailMapperProvider.class, method = "findByAirlinesId")
    List<XtAirlinesAddCostDetailPojo> findByAirlinesId(String airlinesId);

    @DeleteProvider(type = XtAirlinesAddCostDetailMapperProvider.class, method = "delete")
    int delete(String id);

    @Results(id = "xtAirlinesAddCostDetailFinedUKMapId",value = {
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "airlines_id", property = "airlinesId"),
    })
    @SelectProvider(type = XtAirlinesAddCostDetailMapperProvider.class, method = "findUK")
    XtAirlinesAddCostDetailPojo findUK(String name,String airlinesId, String exceptId);

}
